package com.ysh.druid;

import com.ysh.utils.DataSourceUtils;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/*
    Druid工具类测试
 */
public class DruidTest2 {
    public static void main(String[] args) throws Exception {
        // 1.通过连接池的工具类获取一个数据库连接
        Connection con = DataSourceUtils.getConnection();

        String sql = "SELECT * FROM student";

        PreparedStatement pstmt = con.prepareStatement(sql);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()){
            System.out.println(
                    rs.getInt("sid") + "\t"
                            + rs.getString("name") + "\t"
                            + rs.getInt("age") + "\t"
                            + rs.getDate("birthday")
            );
        }
        DataSourceUtils.close(con,pstmt,rs);

    }
}
